<script type='text/javascript'>
	function loginVk()
	{
		window.open(	"http://oauth.vk.com/authorize?client_id={{vk_id}}&redirect_uri=http://{{domain}}/auth/vk&response_type=code&display=popup", 
						"Вход через vk.com",
						"width=400,height=400"
						 ); 
	}
</script>

<div id="fb-root"></div>
<script>
  // Additional JS functions here
	window.fbAsyncInit = function() 
	{
		FB.init(	{
						appId      : '475122522510182', // App ID
						channelUrl : '//{{domain}}/fb_channel.html', // Channel File
						status     : true, // check login status
						cookie     : true, // enable cookies to allow the server to access the session
						xfbml      : true  // parse XFBML
					}
		);

		if (typeof facebookInit == 'function') {
			FB.getLoginStatus(	function(response)
								{
									if (response.status === 'connected') 
									{
										// connected
										//response.accessToken
										//response.userId
									} 
									else  
									{
										loginFb();
									}
								}
			);
		}           

	// Additional init code here

	};

  // Load the SDK Asynchronously
  (function(d){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);
   }(document));

	function loginFb() 
	{
		FB.login(	function( response ) 
					{
						if( response.authResponse ) 
						{
							FB.api('/me',	function(response) 
											{
												$.ajax(	{
															'url': "/auth/fb/",
															'type': "POST",
															'dataType': "json",
															'data': response,
															'success': fbSuccess
														} );	
											}
							);
						} 
						else 
						{
							// cancelled
						}
					}
		);
	}

	function fbSuccess( data )
	{
		document.location.href = data[ 'link' ];
	}
</script>

<div class='margin-top'>
	<table>
		<tr>
			<td valign='middle'>
				<span class='small'>Войти через социальную сеть</span>
			</td>
			<td valign='middle'>
				<div style='margin-left: 7px'><a href='http://oauth.vk.com/authorize?client_id={{vk_id}}&redirect_uri=http://{{domain}}/auth/vk&response_type=code&display=popup' onclick='loginVk()' style='cursor: pointer'><img src='/static/img/vk.png' style='display: block'></a></div>
			</td>
			<td valign='middle'>
				<div style='margin-left: 7px'><a onclick='loginFb()' style='cursor: pointer'><img src='/static/img/fb.png' style='display: block'></a></div>
			</td>
		</tr>
	</table>
</div>
